package com.online.teaching.module.admin.blog.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.online.teaching.dao.BlogMapper;
import com.online.teaching.dao.CommentMapper;
import com.online.teaching.module.admin.blog.domain.vo.GetBlogListVO;
import com.online.teaching.module.admin.blog.domain.vo.GetCommentListVO;
import com.online.teaching.module.admin.blog.service.AdminBlogService;
import com.online.teaching.pojo.Blog;
import com.online.teaching.pojo.Comment;
import com.online.teaching.utils.SmartBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.test.annotation.Rollback;

import java.util.Calendar;
import java.util.List;

/**
 * @ClassName : StudentBlogServiceImpl  //类名
 * @Description :   //描述
 * @Author : YG  //作者
 * @Date: 2020-11-04 13:21  //时间
 */


@Service
public class AdminBlogServiceImpl implements AdminBlogService {

    @Autowired
    private BlogMapper blogMapper;

    @Autowired
    private CommentMapper commentMapper;

    @Override
    public PageInfo<GetBlogListVO> getBlogList(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<Blog> blogs = blogMapper.adminGetBlogList();
        List<GetBlogListVO> getBlogListVOS = SmartBeanUtil.copyList(blogs, GetBlogListVO.class);
        return new PageInfo<>(getBlogListVOS);
    }

    @Override
    public PageInfo<GetCommentListVO> getCommentList(Integer blogId, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<Comment> commentList = commentMapper.adminGetCommentList(blogId);
        List<GetCommentListVO> CommentListVOS = SmartBeanUtil.copyList(commentList, GetCommentListVO.class);
        return new PageInfo<>(CommentListVOS);
    }

    @Rollback
    @Override
    public int deleteBlog(Integer blogId) {
        commentMapper.deleteBlog(blogId);
        int i = blogMapper.deleteBlog(blogId);
        return i;
    }

    @Rollback
    @Override
    public int deleteComment(Integer commentId) {
        //将回复该评论的评论变成直接评论博客的评论
        commentMapper.updateReplyId(commentId);
        int i = commentMapper.deleteComment(commentId);
        return i;
    }

}
